﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReferenceEdit.aspx.cs"
    ValidateRequest="false" Inherits="Habito.Admini.ReferenceEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server"><title>RefrenceEdit</title>
    <script type="text/javascript" src="../../Scripts/jquery-1.4.1.min.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.jbind.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.treeTable.js"> </script>
    <script src="../../Scripts/jquery.easyui.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/jquery.FixedHeadTable.js"> </script>
    <link href="../../Content/jquery.treeTable.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/easyui.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/common.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.form.js" type="text/javascript"></script>
    <script src="../../Scripts/kindeditor-all-min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/kindeditor_zh_cn.js"></script>
    <link rel="stylesheet" href="../../Content/kindeditor_default/default.css" />
    <script type="text/javascript">
        $(function () {
            //上传图片
            $("#btnUpload").click(function () {
                if ($("#flUpload").val() == "") {
                    alert("请选择一个图片文件，再点击上传。");
                    return;
                }
                $('#UpLoadForm').ajaxSubmit({
                    success: function (html, status) {
                        var result = html.replace("<pre>", "");
                        result = result.replace("</pre>", "");
                        var result = html.replace("<PRE>", "");
                        result = result.replace("</PRE>", "");
                        $("#image").attr('src', '..' + result);
                        $("#imageName").val('..' + result);
                        alert(result);
                    }
                });
            });
        });
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="Content"]', {
                resizeType: 1,
                allowPreviewEmoticons: true,
                allowImageUpload: true,
                allowFileManager: true,
                allowUpload: true,
                uploadJson: "../Admini/upload_json.ashx",
                fileManagerJson: '../Admini/file_manager_json.ashx',
                items: ['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
						'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
						'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
						'superscript', 'clearhtml', 'quickformat', 'selectall', '|',
						'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
						'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
						 'table', 'hr', 'pagebreak',
						'anchor', 'link', 'unlink', '|', 'about']
            });
        });
        $(document).ready(function () {
            var id = $("#ID").val();
            if (id != "0") {
                $.ajax({
                    url: window.location.href + "&GetReferenceByID=1",
                    data: {},
                    cache: false,
                    success: function (data) {
                        data = $.evalJSON(data);
                        if (data != null) {
                            $("#year").val(data.RYear);
                            $("#productname").val(data.ProjectName);
                            $("#city").val(data.City);
                            editor.insertHtml(data.Description);
                        }
                    },
                    error: function (data) { }
                });
            }
        });

        function save() {

            var id = $("#ID").val();
            if (id == "") {
                id = 0;
            }
            var year = parseInt($("#year").val());
            if (year > 2020 || year < 1900) {
                alert("Please input a validate Year");
                $("#year").val('').focus();
                return;
            }
            var productname = $("#productname").val();
            var city = $("#city").val();
            var desc = escape(editor.html());
            $.ajax({
                type: 'post',
                url: window.location.href + "&SaveReference=1",
                cache: false,
                data: "year=" + year + "&projectName=" + productname + "&city=" + city + "&description=" + desc,
                success: function () {
                    alert("Reference has Saved");
                    location.href("Reference.aspx");
                },
                error: function (data) {
                }
            });
        }
        function cancel() {
            location.href("Reference.aspx");
        }
    </script>
</head>
<body>
    <div style="width: 100%">
        <input type="hidden" name="name" value=" " />
        <input type="hidden" name="name" id="ID" value="<%=ViewState["id"] %>" />
        Year:<input type="text" name="name" id="year" value="" />
        ProjectName:<input type="text" name="name" id="productname" value="" />
        City:<input type="text" name="name" id="city" value="" />
        <br />
        <form id="UpLoadForm" name="UpLoadForm" method="post" enctype="multipart/form-data"
            action="../PicUploadHander.ashx">
            <table border="0" cellpadding="0" cellspacing="0" class="upp">
                <tr>
                    <td>
                        <img id="image" style="width: 150px; height: 100px;" />
                        <input type="file" id="flUpload" name="flUpload" />
                        <input id="btnUpload" type="button" value="上传" />
                    </td>
                </tr>
            </table>
        </form>
        <input type="button" name="name" value="Save" onclick="save()" />
        <input type="button" name="name" value="Cancel" onclick="cancel()" />
        <div>
            <textarea id="txtContent" name="Content" cols="80" rows="40"></textarea>
        </div>
    </div>
</body>
</html>
